package database.team.phase1;

import java.util.ArrayList;
import java.util.List;

public class QuickSort {
	private static QuickSort instance = null;
	
	private QuickSort(){}
	
	public static QuickSort getInstance(){
		if(instance == null) instance = new QuickSort();
		return instance;
	}

	int partition(List<String> arrString, int left, int right){
		int i = left, j = right;
		String tmp;
		int pivot = Integer.parseInt(arrString.get((left+right)/2).substring(0,7));
		while (i <= j) {
			while (Integer.parseInt(arrString.get(i).substring(0,7)) < pivot)
				i++;
			while (Integer.parseInt(arrString.get(j).substring(0,7)) > pivot)
				j--;
			if (i <= j) {				
				tmp = arrString.get(i);
				arrString.set(i, arrString.get(j));
				arrString.set(j, tmp);
				i++;
				j--;
			}
		};
		return i;
	}
	void quickSort(List<String> arrString, int left, int right) {
		int index = partition(arrString, left, right);
		if (left < index - 1)
			quickSort(arrString, left, index - 1);
		if (index < right)
			quickSort(arrString, index, right);
	}
}